package com.geek.ch02;

/**
 * @author chenmin
 * @desc TODO
 * @date 2025/9/2
 */
public class Person {

    private String name;
    private int age;
    private boolean gender;//true为男，false为女
    private Person partner;//伴侣
    //marry方法
    public void marry(Person p ){
        if(this.gender==p.gender){
            System.out.println(this.name+"和"+p.name+"同性不能结婚");
            return ;
        }
        if(this.gender&&this.age<24||!this.gender&&this.age<22){
            System.out.println(this.name+"未到结婚年龄，不能结婚");
            return ;
        }
        if(p.gender&&p.age<24||!p.gender&&p.age<22){
            System.out.println(p.name+"未到结婚年龄，不能结婚");
            return ;
        }
        if(this.partner!=null||p.partner!=null){
            System.out.println(this.name+"和"+p.name+"某一方已婚，不能结婚");
            return ;
        }
        else {
            System.out.println("恭祝"+this.name+"和"+p.name+"喜结连理");
            this.partner=p;
            p.partner=this;
        }

    }
    //构造方法
    public Person() {
    }

    public Person(String name, int age, boolean gender, Person partner) {
        this.name = name;
        this.age = age;
        this.gender = gender;
        this.partner = partner;
    }

    /**
     * 获取
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取
     * @return age
     */
    public int getAge() {
        return age;
    }

    /**
     * 设置
     * @param age
     */
    public void setAge(int age) {
        this.age = age;
    }

    /**
     * 获取
     * @return gender
     */
    public boolean isGender() {
        return gender;
    }

    /**
     * 设置
     * @param gender
     */
    public void setGender(boolean gender) {
        this.gender = gender;
    }

    /**
     * 获取
     * @return partner
     */
    public Person getPartner() {
        return partner;
    }

    /**
     * 设置
     * @param partner
     */
    public void setPartner(Person partner) {
        this.partner = partner;
    }

    public String toString() {
        return "Person{name = " + name + ", age = " + age + ", gender = " + gender + ", partner = " + partner + "}";
    }
}
